package com.ants.modules.compressUsageLog.service.impl;

import com.ants.common.utils.IPUtils;
import com.ants.modules.compressUsageLog.entity.CompressUsageLog;
import com.ants.modules.compressUsageLog.mapper.CompressUsageLogMapper;
import com.ants.modules.compressUsageLog.service.CompressUsageLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;


/**
 * TODO
 * Author Chen
 * Date   2021/9/7 18:44
 */
@Service
@Slf4j
public class CompressUsageLogServiceImpl extends ServiceImpl<CompressUsageLogMapper, CompressUsageLog> implements CompressUsageLogService {

    @Override
    public void saveCompressUsageLog(HttpServletRequest request, String type) {
      try {
          String ip = IPUtils.getIpAddress(request);
          CompressUsageLog compressUsageLog = new CompressUsageLog();
          compressUsageLog.setType(type);
          compressUsageLog.setIp(ip);
          compressUsageLog.setIpAddress(IPUtils.getLocalCityInfo(ip));
          save(compressUsageLog);
      }catch (Exception e) {
          log.info(e.getMessage());
      }
    }
}
